package webx.actions;

import java.util.Map;

import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;

// import com.genuitec.eclipse.webdesigner3.editors.WebDesignerMultiPageEditor;

public class OperEditorRunnable  implements Runnable{
	
	Map<String, String> result = null;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public OperEditorRunnable(Map result ) {
		this.result = result;
	}
	
	@SuppressWarnings("null")
	public void run() {
		//System.out.println(" run ....... ");
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IEditorPart editor = page.getActiveEditor();
		IDocument doc = null;
		//WebDesignerMultiPageEditor webEditor = null;
		// System.out.println("getActiveEditor:"+editor+"; "+(editor instanceof sssex.editors.MultiPageEditor));
		if(editor instanceof sssex.editors.MultiPageEditor){
			//webEditor = ((sssex.editors.MultiPageEditor)editor).getEditor();
			//doc = ((sssex.editors.MultiPageEditor)editor).doc;
			// com.genuitec.eclipse.webdesigner3.editors.WebDesignerMultiPageEditor pageEdtior
//			((sssex.editors.MultiPageEditor)editor).getEditor().getSourceEditor().getTextViewer().doOperation(org.eclipse.wst.sse.ui.internal.StructuredTextViewer.UNDO);
//			IDocument doc = ((sssex.editors.MultiPageEditor)editor).doc;
//			System.out.println("docq:"+doc.getClass());
//			if (doc instanceof IStructuredDocument){
//				System.out.println("doc:");
//			}
		}
		// TODO Auto-generated method stub
		if("GET".equals(result.get("TYPE"))){
			//System.out.println("GET...");
			result.put("result", doc.get());
		}
		if("SET".equals(result.get("TYPE"))){
			//System.out.println("SET...");
			doc.set((String)result.get("text"));
		}
		if("DOSAVE".equals(result.get("TYPE"))){
			System.out.println("SET...");
			//webEditor.getSourceEditor().doSave(null);
			System.out.println("SAVE...");
		}
		if("UNDO".equals(result.get("TYPE"))){
			System.out.println("SET...");
			//webEditor.getSourceEditor().getTextViewer().doOperation(org.eclipse.wst.sse.ui.internal.StructuredTextViewer.UNDO);
		}
	}

}
